<template>
	<view>
		<!-- 标题开始 -->
		<view class="headline paddiang">
			<text>标题</text>
			<input type="text" placeholder="请输入标题" />
		</view>
		<!-- 标题结束 -->

		<!-- 上传类型 -->
		<view class="uploading paddiang">
			<view>上传类型</view>
			<view class="uni-picker">
				<!-- 滚动选择器 -->
				<view>
					<picker @change="PickerChange" :value="index" :range="picker">
						<view>
							{{picker[index]}}
						</view>
					</picker>
				</view>
				<!-- 右侧箭头 -->
				<view>
					<text class="iconfont icon-search"></text>
				</view>
			</view>
		</view>
		<!-- 上传结束 -->

		<!-- 上传分类 -->
		<view class="uploading paddiang" v-if="index!=0">
			<view>上传分类</view>
			<view class="uni-picker">
				<!-- 滚动选择器 -->
				<view>
					<picker @change="PickerKind" :value="i" :range="pickerKind">
						<view>
							{{pickerKind[i]}}
						</view>
					</picker>
				</view>
				<!-- 右侧箭头 -->
				<view>
					<text class="iconfont icon-search"></text>
				</view>
			</view>
		</view>
		<!-- 上传结束 -->
		
		<!-- 图片上传开始 -->
		<view class="cu-bar bg-white margin-top">
			<view class="action">
				图片上传
			</view>
			<view class="action">
				{{imgList.length}}/1
			</view>
		</view>

		<view class="cu-form-group">
			<view class="grid col-4 grid-square flex-sub">
				<view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage" :data-url="imgList[index]">
					<image :src="imgList[index]" mode="aspectFill"></image>
					<view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="index">
						<text class='cuIcon-close'></text>
					</view>
				</view>
				<view class="solids" @tap="ChooseImage" v-if="imgList.length<1">
					<text class='cuIcon-cameraadd'></text>
				</view>
			</view>
		</view>
		<!-- 图片上传结束 -->
		
		<!-- 上传表情 -->
		<button class="btn">上传表情</button>
		
		<!-- 友情提示 -->
		<view class="hint paddiang">
			<text style="font-size: 28rpx;font-weight: 700;">友情提示</text>
			<text>内容被他人下载成功,保存成功后奖励<text style="color: #e21918;">0.5积分</text></text>
			<text>发表的内容经过人工审核确认无任何色情,低俗,暴力,政治,违法等令人不合的内容后方可显示</text>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				i: 0,
				index: 0,
				picker: ['请选择', '表情', '头像', '壁纸'],
				pickerKind: ['请选择', '情侣', '抖音', '潮女', '潮男', '动漫女头', '动漫男头', '搞笑'],
				imgList: [],// 用户上传的图片
			};
		},
		methods: {
			// 上传类型选择
			PickerChange(e) {
				this.index = e.target.value
			},
			// 上传分类选择
			PickerKind(e) {
				this.i = e.target.value
			},
			// 预览图片
			ViewImage(e) {
				uni.previewImage({
					urls: this.imgList,
					current: e.currentTarget.dataset.url
				});
			},
			// 点击删除图片
			DelImg(e) {
				uni.showModal({
					title: '提示',
					content: '确定要删除这张图片吗??',
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							this.imgList.splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			},
			// 点击上传图片
			ChooseImage() {
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						if (this.imgList.length != 0) {
							this.imgList = this.imgList.concat(res.tempFilePaths)
						} else {
							this.imgList = res.tempFilePaths
						}
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	// 输入标题
	.headline {
		height: 100rpx;
		background-color: #fff;
		display: flex;
		align-items: center;
		margin-top: 20rpx;

		input {
			margin-left: 20rpx;
		}
	}

	// 上传类型
	.uploading {
		height: 100rpx;
		margin-top: 20rpx;
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.iconfont {
		font-size: 22rpx;
		margin-left: 20rpx;
	}

	.uni-picker {
		display: flex;
	}
	// 上传表情按钮样式
	.btn{
		width: 200rpx;
		height: 80rpx;
		background-color: #fdd201;
		font-size: 26rpx;
		margin: 50rpx auto 20rpx;
		border-radius: 40rpx;
	}
	.hint{
		display: flex;
		flex-direction: column;
		font-size: 24rpx;
		line-height: 50rpx;
		color: #888;
	}
</style>
